package eu.reply.android.flashm.entities;

import org.json.JSONException;
import org.json.JSONObject;

public class ProfileFactory {

	protected static String PROFILE_ID="profileId";
	protected static String NAME="name";
	protected static String IMAGE="image";
	protected static String REGISTRATION_ID="registrationId";
	
	
	public static Profile parseJSON(String jsonString) throws JSONException{
		Profile profile=null;
		
		JSONObject json=new JSONObject(jsonString);
		int profileId=json.optInt(PROFILE_ID,0);
		String name= json.optString(NAME);
		String image= json.optString(IMAGE);
		String regID=json.optString(REGISTRATION_ID);
		
		profile = new Profile(profileId,name);
		profile.setImageUri(image);
		profile.setRegistrationID(regID);
		
		return profile;
		
	}
	
	public static String toJSONString(Profile profile) throws JSONException{
		
		JSONObject json = new JSONObject();	
		json.put(PROFILE_ID, profile.getId());
		json.put(NAME, profile.getName());
		json.put(IMAGE, profile.getImageUri());
		json.put(REGISTRATION_ID, profile.getRegistrationID());
		
		return json.toString();
	}
	
}
